﻿namespace Ruirun.Mes.Dtos
{
    [MapTo(typeof(MaterialCategory))]
    public class MaterialCategoryInputDto : IInputDto<Guid>
    {
        public Guid Id { get; set; }

        public Guid? ParentId { get; set; }

        public string Name { get; set; }

        public string Description { get; set; }

        public string TreePathString { get; set; } = string.Empty;
    }

    [MapFrom(typeof(MaterialCategory))]
    public class MaterialCategoryOutputDto : IOutputDto
    {
        public Guid Id { get; set; }

        public Guid? ParentId { get; set; }

        public string Name { get; set; }

        public string Description { get; set; }

        public string TreePathString { get; set; }

    }

    [MapFrom(typeof(MaterialCategory))]
    public class MaterialCategoryNodeDto : MaterialCategoryOutputDto
    {
        public MaterialCategoryNodeDto() { }

        public MaterialCategoryNodeDto(MaterialCategory m)
        {
            this.Id = m.Id;
            this.ParentId = m.ParentId;
            this.Name = m.Name;
            this.Description = m.Description;
            this.TreePathString = m.TreePathString;
        }

        /// <summary>
        /// 获取 层级
        /// </summary>
        public int Level { get { return TreePathString.IsNullOrWhiteSpace() ? -1 : TreePathString.Split(',').Length; } }

    }

    [MapFrom(typeof(MaterialCategory))]
    public class MaterialCategoryTreeNodeDto : MaterialCategoryNodeDto
    {
        /// <summary>
        /// 获取 是否有子项
        /// </summary>
        public bool HasChildren => Children != null && Children.Count > 0;

        /// <summary>
        /// 获取 子项集合
        /// </summary>
        public List<MaterialCategoryTreeNodeDto> Children { get; set; }

    }

}